package rserver
import(
	"github.com/lesismal/arpc"
	"gintest/core/consul"
	"strconv"
)
type Ctx =*arpc.Context
type RpcServer struct{
	server *arpc.Server
	ip string
	port int
	Handler func(*RpcServer)
}
func NewServer(ip string,port int) *RpcServer{
	return &RpcServer{
		server:arpc.NewServer(),
		ip:ip,
		port:port,
	}
}
func (this *RpcServer)Close(){
	this.server.Stop()
}
func (this *RpcServer)Bind(name string,fc func(Ctx)){
	consul.Register(name,this.ip,this.port)
	this.server.Handler.Handle(name,fc)
}

func (this *RpcServer)Run() error{
	this.Handler(this)
	return this.server.Run(":"+strconv.Itoa(this.port))
}